package javolution.context;

import javolution.lang.Configurable;

/* loaded from: classes2.dex */
public abstract class SecurityContext extends Context {
    private static volatile SecurityContext _Default = new Default();
    public static final Configurable<Class<? extends SecurityContext>> DEFAULT = new Configurable(_Default.getClass()) { // from class: javolution.context.SecurityContext.1
        @Override // javolution.lang.Configurable
        protected void notifyChange() {
            SecurityContext unused = SecurityContext._Default = (SecurityContext) ObjectFactory.getInstance((Class) get()).object();
        }
    };

    /* loaded from: classes2.dex */
    private static class Default extends SecurityContext {
        private Default() {
        }
    }

    static {
        ObjectFactory.setInstance(new ObjectFactory() { // from class: javolution.context.SecurityContext.2
            /* JADX INFO: Access modifiers changed from: protected */
            @Override // javolution.context.ObjectFactory
            public Object create() {
                return new Default();
            }
        }, _Default.getClass());
    }

    protected SecurityContext() {
    }

    public static SecurityContext getCurrent() {
        for (Context current = Context.getCurrent(); current != null; current = current.getOuter()) {
            if (current instanceof SecurityContext) {
                return (SecurityContext) current;
            }
        }
        return _Default;
    }

    public static SecurityContext getDefault() {
        return _Default;
    }

    @Override // javolution.context.Context
    protected final void enterAction() {
        SecurityContext securityContext = _Default;
        Context outer = getOuter();
        while (true) {
            if (outer == null) {
                break;
            } else if (outer instanceof SecurityContext) {
                securityContext = (SecurityContext) outer;
                break;
            } else {
                outer = outer.getOuter();
            }
        }
        if (!securityContext.isReplaceable()) {
            throw new SecurityException("Current Security Context not Replaceable");
        }
    }

    @Override // javolution.context.Context
    protected final void exitAction() {
    }

    public boolean isModifiable(Configurable configurable) {
        return true;
    }

    public boolean isReplaceable() {
        return true;
    }
}
